import {
  DeleteDateColumn,
  Entity,
  JoinColumn,
  ManyToOne,
  OneToOne,
} from 'typeorm';
import { BaseToken } from './baseToken.entity';
import { FreshToken } from './freshToken.entity';
import { UserEntity } from '@/modules/User/entities/user.entity';
import { Type } from 'class-transformer';

@Entity('access_token')
export class AccessToken extends BaseToken {
  @OneToOne(
    (type) => FreshToken,
    (freshToken: FreshToken) => freshToken.accessToken,
    {
      cascade: true,
      onDelete: 'CASCADE',
    },
  )
  freshToken!: FreshToken;

  @ManyToOne((type) => UserEntity, (user: UserEntity) => user.accessToken, {
    onDelete: 'CASCADE',
  })
  user: UserEntity;
}
